package com.xposed.xinhao;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.webkit.WebView;

import com.xposed.xinhao.hook_jingdong.JingdongHook;
import com.xposed.xinhao.hook_microsupply.MicrosupplyHook;
import com.xposed.xinhao.hook_momo.MomoHook;
import com.xposed.xinhao.hook_newmbank.NewmbankHook;
import com.xposed.xinhao.hook_pinduoduo.PddSellerHook;
import com.xposed.xinhao.hook_weixin.WechatHook;
import com.xposed.xinhao.hook_yiqianbao.YiqianbaoHook;
import com.xposed.xinhao.utils.JsonUtils;
import com.xposed.xinhao.utils.LogUtils;

import java.util.Set;

import de.robv.android.xposed.IXposedHookLoadPackage;
import de.robv.android.xposed.XC_MethodHook;
import de.robv.android.xposed.XposedBridge;
import de.robv.android.xposed.XposedHelpers;
import de.robv.android.xposed.callbacks.XC_LoadPackage;

/**
 * @author Administrator
 */
public class MainXposed implements IXposedHookLoadPackage {

    @Override
    public void handleLoadPackage(final XC_LoadPackage.LoadPackageParam lpparam) throws Throwable {

        String packageName = lpparam.processName;

        //HOOK 易钱包
        if (packageName.equals("com.yeepay.mpos.money")) {
            LogUtils.e("HOOK【易钱包】主进程：" + packageName);
            YiqianbaoHook hook = new YiqianbaoHook(lpparam);
            hook.hookMethod();
        }

        //拼多多商家
        if (packageName.equals("com.xunmeng.merchant")) {
            LogUtils.e("HOOK【拼多多商家】主进程：" + packageName);
            PddSellerHook hook = new PddSellerHook(lpparam);
            hook.hookMethod();
        }

        //民生银行
        if (packageName.equals("cn.com.cmbc.newmbank")) {
            LogUtils.e("HOOK【民生银行】主进程：" + packageName);
            NewmbankHook hook = new NewmbankHook(lpparam);
            hook.hookMethod();
        }

        //HOOK 微信
        if (packageName.equals("com.tencent.mm")) {
            XposedBridge.log("HOOK【微信】主进程：" + packageName);
            WechatHook hook = new WechatHook(lpparam);
            hook.hookMethod();
        }

        //HOOK 采源宝
        if (packageName.equals("com.alibaba.wireless.microsupply")) {
            XposedBridge.log("HOOK【采源宝】主进程：" + packageName);
            MicrosupplyHook hook = new MicrosupplyHook(lpparam);
            hook.hookMethod();
        }

        //HOOK 京东
        if (packageName.equals("com.jingdong.app.mall")) {
            XposedBridge.log("HOOK【京东】主进程：" + packageName);
            JingdongHook hook = new JingdongHook(lpparam);
            hook.hookMethod();
        }

        //HOOK 陌陌
        if (packageName.equals("com.immomo.momo")) {
            XposedBridge.log("HOOK【陌陌】主进程：" + packageName);
            MomoHook hook = new MomoHook(lpparam);
            hook.hookMethod();
        }


        //HOOK 云闪付
        if (packageName.equals("com.unionpay")) {
            LogUtils.e("HOOK【云闪付】主进程：" + packageName);

            //屏蔽更新
            XposedHelpers.findAndHookMethod("com.unionpay.base.UPActivityBase"
                    , lpparam.classLoader
                    ,"a"
                    , lpparam.classLoader.loadClass("com.unionpay.network.model.UPUpdateInfo"), new XC_MethodHook() {
                        @Override
                        protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
                            super.beforeHookedMethod(param);
                            LogUtils.e("hook到了UPDialog创建3" + JsonUtils.objectToString(param.args[0]));
                            param.args[0]=null;
                        }
                    });
            //屏蔽更新
            XposedHelpers.findAndHookMethod("com.unionpay.activity.react.UPReactNativeActivity"
                    , lpparam.classLoader
                    ,"a"
                    , lpparam.classLoader.loadClass("com.unionpay.network.model.UPUpdateInfo"), new XC_MethodHook() {
                        @Override
                        protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
                            super.beforeHookedMethod(param);
                            LogUtils.e("------" + JsonUtils.objectToString(param.args[0]));
                            param.args[0]=null;
                        }
                    });

//            XposedHelpers.findAndHookConstructor("com.unionpay.base.UPDialog", lpparam.classLoader, Context.class, lpparam.classLoader.loadClass("com.unionpay.base.UPDialog$UPDialogParams"), new XC_MethodHook() {
//                @Override
//                protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
//                    super.beforeHookedMethod(param);
//                }
//            });
//
//            XposedHelpers.findAndHookMethod("com.unionpay.base.UPDialog", lpparam.classLoader, "setCancelable",boolean.class, new XC_MethodHook() {
//                @Override
//                protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
//                    super.beforeHookedMethod(param);
//                    LogUtils.e("------" + param.args[0]);
//                }
//            });

        }

    }//https://m.immomo.com/s/account/pwd_recover/login_difficult.html?_bid=0

}
